from selenium import webdriver
from datetime import datetime
from selenium.webdriver.common.by import By
import time
import os

time1=datetime.now()
today = time1.strftime('%Y-%m-%d')




driver = webdriver.Chrome()
driver.get('https://mail.163.com/')
driver.maximize_window()

#定位
path =os.path.join(os.path.abspath('163日报'),'2022-9-11dyh.txt')
# path2 =os.path.join(os.path.abspath('163日报'),f'{today}dyh.txt')
# 切换iframe
a=driver.find_element(By.TAG_NAME,'iframe')
driver.switch_to.frame(a)
driver.find_element(By.NAME,"email").send_keys('a2320083160')
driver.find_element(By.NAME,"password").send_keys('dyh730201!')
driver.find_element(By.ID,'dologin').click()
time.sleep(2)
driver.find_element(By.XPATH,'//li[@id="_mail_component_149_149"]/span').click()

# 收件人
driver.find_element(By.CLASS_NAME,'nui-editableAddr-ipt').send_keys('"我"<a2320083160@163.com>')
time.sleep(2)
#主题
driver.find_element(By.XPATH,"//input[contains(@id,'_subjectInput')]").send_keys('哈哈哈')

# b=driver.find_element(By.TAG_NAME,'//iframe[3]')
# driver.switch_to.frame(b)
#上传附件
driver.find_element(By.XPATH,'//input[@type="file"]').send_keys(path)

#选中输入框
d=driver.find_element(By.CLASS_NAME,'APP-editor-iframe')
driver.switch_to.frame(d)
e=driver.find_element(By.XPATH,'//body[@class="nui-scroll"]')
e.click()
e.send_keys('啦啦啦啦啦')

driver.switch_to.default_content()
driver.find_element(By.XPATH,'//footer//b[1]').click()#点击发送


time.sleep(5)
driver.quit()








